import { mapState, createNamespacedHelpers,  } from "vuex";
import { useMapper } from "./useMapper";

export const useState = (moduleName: any, mappr: any) => {
  let mapperFn = mapState;
  
  //取模块中的state
  if (typeof moduleName === "string" && moduleName.length > 0) {
    mapperFn = createNamespacedHelpers(moduleName).mapState
    return useMapper(mappr, mapperFn)
  } else {
    //取根模块
    return useMapper(moduleName, mapState)
  }
} 